# 李广龙
# 服务器sh脚本
# 0.40 版本
#echo

SERVICE_PATH="/var/jenkins_home"
SERVICE_NAME="jenkins"

creatConfig() {
mkdir -p $SERVICE_PATH
chmod 777 $SERVICE_PATH
}
creatStart() {
  creatConfig
  start
  cd $SERVICE_PATH || exit
  cd $SERVICE_PATH || exit
cat >./hudson.model.UpdateCenter.xml <<EOF
<?xml version='1.1' encoding='UTF-8'?>
<sites>
  <site>
    <id>default</id>
    <url>https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json</url>
  </site>
</sites>
EOF

cat $SERVICE_PATH/secrets/initialAdminPassword
# 可能权限不够 手动查看下
}

start() {
  # docker pull jenkins/jenkins

  docker run -d -p 10240:8080 -p 10241:50000 -v $SERVICE_PATH:/var/jenkins_home -v /etc/localtime:/etc/localtime --name $SERVICE_NAME jenkins/jenkins
  docker ps -a | grep "$SERVICE_NAME"
  echo "$SERVICE_NAME""运行成功！"
  echo "完成！"
}

read -p '输入功能编号 0:创建挂载运行 1:挂载运行: (任意键退出)' input
echo "输入编号:$input"

case $input in
    0)
    creatStart
    ;;
    1)
    start
    ;;
    *)
    echo -e "${RED}退出sh脚本${RES}"
    exit 0
    ;;
  esac

